Repository navigation
searcher: fix cache size env vars rendering 0 for non-Gi storageSize - #948
Merged
Merged
Conversation
SEARCHER_CACHE_SIZE_MB and SYMBOLS_CACHE_SIZE_MB were derived with trimSuffix "Gi" | mul 450, so a storageSize like 150G left a non-numeric string that sprig cast to 0. searcher treats 0 as "never evict", so both caches grew unbounded until the PVC filled and the pod failed to start with "failed to setup TMPDIR: ... no space left on device". Move the math into a sourcegraph.searcher.cacheSizeMB helper in its own file under templates/_helpers/. It accepts a whole number of M, Mi, G or Gi and fails the render on anything else, unless searcher.autoCacheSize is enabled (the env vars are omitted in that case). Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-01a146da-9505-715c-949c-1146cc4e7e33
marcleblanc2
force-pushed
the
searcher-storagesize-g-units
branch
from
October 16, 2026 22:39
c3ca70d to
e203311
Compare
Contributor
|
I don't mind this, but it seems like it might be a little auto magic for the style we typically take with our manifests. I'd like to get a second opinion from someone else on the team, wdyt @filiphaftek ? |
…arser (#965) Follow-up to #948, targeting its branch so it can be merged into the same fix. #948's allowlist (`M|Mi|G|Gi`) turns `1Ti` and other valid PVC sizes from "silently renders `0`" into "`helm upgrade` refuses", and it can still render `0` for `0G`/`1M`/`2M`, which searcher treats as "never evict". This extracts the Kubernetes quantity parser that `sourcegraph.redis.maxmemory` already had into a shared `sourcegraph.quantityBytes` helper and uses it for `searcher.storageSize`, so any quantity (`1Ti`, `1.5G`, `1024Ki`, suffixless bytes) works and the parser is defined once. The 45% is computed the way searcher auto-sizes (`floor(bytes/1e6) * 45 / 100`) instead of treating `Gi` as `G`, and the render fails when the result would be `0`. Behaviour change to be aware of: existing `Gi` deployments get a slightly higher value on upgrade (default `26Gi`: `11700` → `12562`), called out in the CHANGELOG. ## Test plan `helm unittest charts/sourcegraph` (195 passed, incl. the unchanged Redis `maxmemory` suite covering the extracted parser), `helm lint`, `./scripts/helm-docs.sh` clean. | `searcher.storageSize` | `main` | #948 | this PR | |---|---|---|---| | `26Gi` (default) | `11700` | `11700` | `12562` | | `150G` | `0` | `67500` | `67500` | | `1Ti` | `0` | render fails | `494779` | | `1.5G` | `0` | render fails | `675` | | `2M` / `0G` | `0` | `0` | render fails | | `1Tb` | `0` | render fails | render fails | | `1Tb` + `autoCacheSize: true` | omitted | omitted | omitted | Co-authored-by: Amp <amp@ampcode.com>
marcleblanc2
enabled auto-merge (squash)
October 19, 2026 20:34
michaellzc
approved these changes
Oct 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the issue for impacted customers without requiring them to change their deployment, beyond upgrading.
Problem
SEARCHER_CACHE_SIZE_MBandSYMBOLS_CACHE_SIZE_MBwere derived withtrimSuffix "Gi" .Values.searcher.storageSize | mul 450. Any other valid PVC size (150G,1Ti,500000M) left a non-numeric string that sprig cast to0, so both env vars rendered"0".searcher treats an explicit
0as "never evict" (an unset variable auto-sizes instead), so both caches grew unbounded until the PVC filled and the pod failed to start:Reported by a customer with
searcher.storageSize: 150Gafter upgrading 6.5.0 → 7.2.0. The template has behaved this way since v6.4 (#677), so the disk had been filling for months; it was only noticed in the logs after the upgrade.Fix
sourcegraph.redis.maxmemoryalready had into a sharedsourcegraph.quantityByteshelper intemplates/_helpers.tpl. Accepts any quantity suffix (k/M/G/T/P/E, theiribinary forms, fractional values, suffixless bytes).sourcegraph.searcher.cacheSizeMBhelper intemplates/_helpers/_searcherCacheSize.tpluses it to computefloor(bytes / 1e6) * 45 / 100, the same arithmetic searcher uses when it auto-sizes from the volume.searcher.autoCacheSize=true, when the value is unparseable or so small the result would be0(anything under3M). Silently disabling eviction is no longer possible.searcher.StatefulSet.yamlcall the helper.values.yamlcomment, README (helm-docs), CHANGELOG, and a newsearcherCacheSize_test.yamlsuite.Behaviour change for existing deployments
Binary units are now converted exactly instead of being treated as decimal, so every
Gideployment renders a slightly higher value and searcher pods restart on upgrade. The default26Gigoes from11700to12562;100Gifrom45000to48318. These match what searcher's auto-sizing would pick for the same disk.Two caches at 45% each is 90% of the nominal PVC. The old
Gi × 450math happened to leave more slack (2 × 11700 MB is 84% of 26Gi). searcher's auto mode uses 90% of the mounted filesystem, which is a few percent smaller than the PVC request, and TMPDIR shares the volume. Operators who want more headroom should enablesearcher.autoCacheSize.Verification
searcher.storageSize26Gi)1170012562100Gi4500048318150G0(no eviction)675001Ti0(no eviction)4947791.5G0(no eviction)675500000M0(no eviction)2250006442450944(bytes)0(no eviction)28983M0(no eviction)12M,0G0(no eviction)1Tb0(no eviction)1Tb+autoCacheSize: true